package intant.logger.test;

import com.ilikesoup.instant.logger.BeanMonitor;
import lombok.Data;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

public class BeanPropertyChangeLogTestCase {

    @Test
    public void testNewInstance() {
        A bean = BeanMonitor.newInstance(A.class,"name");
        bean.setName("xxl");
        bean.setName("xxx");
        bean.setAge(111);
    }

    @Test
    public void testWrap() {
        A a = new A();
        a.setName("small");
        a.setAge(11);
        A wrap = BeanMonitor.wrap(a);
        System.out.println(wrap);
        wrap.setName("abc");
    }

    @Test
    public void testList() {
        B b = BeanMonitor.newInstance(B.class);
        List<C> list = new ArrayList<>();
        b.setList(list);
        list.add(new C());
        // not support
    }

    @Test
    public void testDeep() {
        System.setProperty("cglib.debugLocation", "D:\\soup\\instant-soup\\src\\test\\java\\intant\\logger\\test\\");
        A a = new A();
        A wrap = BeanMonitor.wrap(a);
        C c = new C();
        wrap.setC(c);
        wrap.c.setNick("jack");
    }


    @Test
    public void testDeep2() {
        System.setProperty("cglib.debugLocation", "C:\\Users\\Thin'k'pa'd\\");
        A a = new A();
        A wrap = BeanMonitor.wrap(a);
        C c = new C();
        c = BeanMonitor.wrap(c);
        c.setNick("jack");
        System.out.println(wrap);
    }

    @Data
    public static class A {
        private String name;
        private int age;
        private C c;

        @Override
        public String toString() {
            return "A{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    ", c=" + c +
                    '}';
        }
    }

    @Data
    public static class B extends A{
        private List<C> list;

    }

    @Data
    public static class C {
        private String nick;

        @Override
        public String toString() {
            return "C{" +
                    "nick='" + nick + '\'' +
                    '}';
        }
    }

}
